using System;
using System.Reflection;
/// <summary>
/// Type扩展
/// </summary>
public static class HFTypeExtend
{
    /// <summary>
    /// 类型是否是值类型
    /// </summary>
    /// <param name="_type">类型</param>
    /// <returns>true:是值类型,false:不是值类型</returns>
    public static bool HFIsValueType(this Type _type)
    {
        return _type.IsValueType || _type.Equals(typeof(string));
    }
    /// <summary>
    /// 是否是静态类
    /// </summary>
    /// <param name="_type">源类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsStatic(this Type _type)
    {
        return _type.IsSealed && _type.IsAbstract;
    }

    /// <summary>
    /// 是否是指定类别或指定类别的子类别
    /// </summary>
    /// <param name="_srctype">源类别</param>
    /// <param name="_ofType">指定类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsTypeOrSubTypeOf(this Type _srctype, Type _ofType)
    {
        return _srctype.HFIsTypeOf(_ofType) || _srctype.HFIsSubTypeOf(_ofType);
    }

    /// <summary>
    /// 是否是指定类别或指定类别的子类别非抽象类
    /// </summary>
    /// <param name="_srctype">源类别</param>
    /// <param name="_ofType">指定类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsTypeOrSubTypeOfNotAbstract(this Type _srctype, Type _ofType)
    {
        return _srctype.HFIsTypeOrSubTypeOf(_ofType) && !_srctype.IsAbstract;
    }

    /// <summary>
    /// 是否是指定类别
    /// </summary>
    /// <param name="_srctype">源类别</param>
    /// <param name="_ofType">指定类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsTypeOf(this Type _srctype, Type _ofType)
    {
        return _srctype.Equals(_ofType);
    }

    /// <summary>
    /// 是否是指定类别的子类别
    /// </summary>
    /// <param name="_srctype">源类别</param>
    /// <param name="_ofType">指定类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsSubTypeOf(this Type _srctype, Type _ofType)
    {
        return _srctype.IsSubclassOf(_ofType) || _srctype.GetInterface(_ofType.Name) != null;
    }

    /// <summary>
    /// 是否是指定类别的子类别非抽象类
    /// </summary>
    /// <param name="_srctype">源类别</param>
    /// <param name="_ofType">指定类别</param>
    /// <returns>True:是,False:否</returns>
    public static bool HFIsSubTypeOfNotAbstract(this Type _srctype, Type _ofType)
    {
        return _srctype.HFIsSubTypeOf(_ofType) && !_srctype.IsAbstract;
    }

    /// <summary>
    /// 是否是纯方法
    /// </summary>
    /// <param name="_methodInfo">方法</param>
    /// <returns>true:是,false:否</returns>
    public static bool HFIsMethod(this MethodInfo _methodInfo)
    {
        return !_methodInfo.IsSpecialName;
    }


    /// <summary>
    /// 获取类型的默认值
    /// </summary>
    /// <param name="_type">类型</param>
    /// <returns></returns>
    public static object HFDefaultValue(this Type _type)
    {
        return _type.IsValueType ? Activator.CreateInstance(_type) : null;
    }
}